<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>随笔详情</title>
    <link rel="stylesheet" href="css/conmmon.css">
    <link rel="stylesheet" href="css/blog_content.css">
    <link rel="stylesheet" href="editor.md/css/editormd.preview.min.css" />
    <script src="js/jquery.min.js"></script>
    <script src="editor.md/editormd.js"></script>
    <script src="editor.md/lib/marked.min.js"></script>
    <script src="editor.md/lib/prettify.min.js"></script>
    <script src="js/common.js"></script>
</head>

<body>
    <!-- 导航栏 -->
    <div class="nav">
        <img src="img/logo2.jpg" alt="">
        <span class="title">个人随笔分享平台</span>
        <!-- 用来占据中间位置 -->
        <span class="spacer"></span>
        <a href="blog_list.html">随笔主页</a>
        <a href="blog_add.html">写随笔</a>
        <a href="myblog_list.html">我的随笔</a>
        <a href="my_draftbox.html">草稿箱</a>
        <a href="login.html">登录</a>
    </div>
    <!-- 版心 -->
    <div class="container">
        <!-- 左侧个人信息 -->
        <div class="container-left">
            <div class="card">
                <img src="img/doge.jpg" class="avtar" alt="">
                <h4 id="nickname"></h4>
                <a href="https://www.gitee.com">gitee 地址</a>
                <div class="counter">
                    <span>文章</span>
                    <span>访问量</span>
                </div>
                <div class="counter">
                    <span id="artCount"></span>
                    <span id="allReadCount"></span>
                </div>
            </div>
        </div>
        <!-- 右侧内容详情 -->
        <div class="container-right">
            <div class="blog-content">
                <!-- 博客标题 -->
                <h3 id="title"></h3>
                <!-- 博客时间 -->
                <div class="date">
                    发布时间: <span id="createtime"></span>&nbsp;&nbsp;
                    修改时间：<span id="updatetime"></span>&nbsp;&nbsp;
                    阅读量：<span id="rcount"></span>
                </div>
                <!-- 博客正文 -->
                <div id="editorDiv">

                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
            var editormd;
            function initEdit(md){
                editormd = editormd.markdownToHTML("editorDiv", {
                markdown : md, // Also, you can dynamic set Markdown text
                // htmlDecode : true,  // Enable / disable HTML tag encode.
                // htmlDecode : "style,script,iframe",  // Note: If enabled, you should filter some dangerous HTML tags for website security.
                });
            }
            // 获取文章详情
            function getArtDetail(id) {
                if(id == "") {
                    alert("非法参数!");
                    return;
                }
                jQuery.ajax({
                    url:"/art/detail",
                    type:"POST",
                    data:{"id":id},
                    success:function(result) {
                        if(result != null && result.code == 200 && result.data != null) {
                            // 查询成功
                            // 展示标题、时间、阅读量以及文章内容信息
                            jQuery("#title").html(result.data.title);
                            jQuery("#createtime").html(result.data.createtime);
                            jQuery("#updatetime").html(result.data.updatetime);
                            jQuery("#rcount").html(result.data.rcount);
                            initEdit(result.data.content);
                            // 用户 id 为 result.data.uid
                            showAuthor(result.data.uid); // 展示左侧作者信息
                        } else {
                            // 查询失败
                            alert("发生了未知错误, 请稍后再试！");
                            return;
                        }
                    }
                });
            }
            getArtDetail(getUrlValue("id"));
            // 展示作者信息
            function showAuthor(uid) {
                jQuery.ajax({
                    url:"/user/getuserbyid",
                    type:"POST",
                    data:{"id":uid},
                    success:function(result) {
                        if(result != null && result.code == 200 && result.data != null && result.data.id > 0) {
                            // 设置作者姓名及文章数量
                            jQuery("#nickname").html(result.data.nickname);
                            jQuery("#artCount").html(result.data.artCount)
                            jQuery("#allReadCount").html(result.data.allReadCount);
                        } else {
                            alert("发生了未知错误, 请稍后再试！");
                            return;
                        }
                    }
                });
            }
            // 更新阅读量
            function updateRCount() {
                var id = getUrlValue("id");
                if(id != null && id != ""){
                    jQuery.ajax({
                        url:"/art/updatercount",
                        type:"POST",
                        data:{"id":id},
                        success:function(result){}
                    });
                }
            }
            updateRCount();
    </script> 
</body>

</html>